home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / CBalloonKeyAttach 1.0 / CBalloonKeyAttach.cp next >
Encoding:
Text File  |  1996-05-16  |  1.7 KB  |  58 lines  |  [TEXT/CWIE]

  1. // ===========================================================================
  2. // • CBalloonKeyAttachment                               CBalloonKeyAttachment •
  3. // ===========================================================================
  4. //    Allows the "Help" key to toggle balloon help off and on. 
  5. //
  6. //    Last update: Paul Robichaux <paul@ljl.com>, 5/16/96
  7. //
  8. //  ©1996 Paul Robichaux. All rights reserved. Free for use in noncommercial or 
  9. //  shareware products; contact author for other uses. As a courtesy, please send
  10. //  me bug reports, updates, or improvement suggestions if you have 'em.
  11. //
  12. //    For use only with msg_KeyPress. You could add behaviors so that BH gets disabled
  13. //  on suspend and re-enabled on resume, but this might violate the principle of
  14. //  least astonishment-- OTOH I hate seeing balloons when I to an app where I don't
  15. //  need them.
  16. //
  17. //  To use, just attach to a commander-- no muss, no fuss.
  18.  
  19.  
  20.  
  21. #include "CBalloonKeyAttach.h"
  22. #include <PP_KeyCodes.h>
  23.  
  24.  
  25. CBalloonKeyAttachment::CBalloonKeyAttachment()
  26.         : LAttachment(msg_KeyPress)
  27. {
  28.     mBalloonState = ::HMGetBalloons();
  29. }
  30.  
  31.  
  32. // Default destructor doesn't do anything
  33. CBalloonKeyAttachment::~CBalloonKeyAttachment()
  34. {
  35. }
  36.  
  37.  
  38. void CBalloonKeyAttachment::ExecuteSelf(MessageT     inMessage,        // ignored
  39.                                         void        *ioParam)
  40. {
  41.     Int16    theKey = ((EventRecord*)ioParam)->message & charCodeMask;
  42.     mExecuteHost = true;
  43.     
  44.     // If it's the Help key, toggle the balloon state if the state we have
  45.     // matches what we expect. If they don't match, it likely means that the user
  46.     // toggled the state manually, so don't re-toggle it. 
  47.     if (char_Help == theKey)
  48.     {
  49.         if (::HMGetBalloons() == mBalloonState)
  50.         {
  51.             mBalloonState = !mBalloonState;
  52.             ::HMSetBalloons(mBalloonState);
  53.             mExecuteHost = false;
  54.         }
  55.     }
  56. }
  57.  
  58.